<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>翻转单词顺序</title>
</head>
<body>
<script>
    /*
          输入: "the sky is blue"
          输出: "blue is sky the"
     */
    let str = " the    sky is blue  ";//blue is sky the
    let reverseWords = function (s) {
        let arr = s.split(" ").filter(Boolean);
        let start = 0;
        let end = arr.length - 1;
        while (start < end) {
            [arr[start],arr[end]] = [arr[end],arr[start]];
            start++;
            end--;
        }
        return arr.join(" ");
    };
    console.log(reverseWords(str));
</script>
</body>
</html>